﻿package view.prompt
{
    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.display.*;
    import flash.events.*;
    import morn.core.components.*;
    import morn.core.handlers.*;

    public class ImgPromptCell extends Sprite implements IPrompt
    {
        private var img:Image;
        private var _changeHandler:Handler;
        public var _btnMsg:Object;
        protected var tweenMax:TweenMax;

        public function ImgPromptCell()
        {
            return;
        }// end function

        public function createCell(param1:Sprite, param2:Object, param3:Handler) : void
        {
            param1.addChild(this);
            this.visible = false;
            this._btnMsg = param2;
            this._changeHandler = param3;
            this.img = new Image(PromptProtocol.sourcePath + param2.name);
            this.addChild(this.img);
            this.initEvent();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            this.visible = true;
            if (this._changeHandler)
            {
                this._changeHandler.execute();
            }
            if (this.tweenMax == null)
            {
                this.alpha = 1;
                this.tweenMax = TweenMax.to(this, 0.6, {alpha:0, yoyo:true, repeat:int.MAX_VALUE, ease:Sine.easeIn});
            }
            return;
        }// end function

        public function hide() : void
        {
            this.visible = false;
            if (this._changeHandler)
            {
                this._changeHandler.execute();
            }
            if (this.tweenMax != null)
            {
                this.tweenMax.kill();
                this.tweenMax = null;
            }
            return;
        }// end function

        public function initEvent() : void
        {
            this.img.addEventListener(MouseEvent.CLICK, this.doMouse);
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public function removeEvent() : void
        {
            this.img.removeEventListener(MouseEvent.CLICK, this.doMouse);
            return;
        }// end function

        public function destroy() : void
        {
            if (this.img)
            {
                this.removeEvent();
                if (this.img.parent)
                {
                    this.img.parent.removeChild(this.img);
                }
                this.img = null;
            }
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            this._changeHandler = null;
            if (this.tweenMax)
            {
                this.tweenMax.kill();
                this.tweenMax = null;
            }
            return;
        }// end function

    }
}
